﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Business;

namespace WebApplication1
{
    public partial class MyOrder : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BindData();
            
        }

       public void BindData()
        {
            Business.User userobj = (User)Session["User"];
            Order myorder = new Order();
            lsvOrders.DataSource = myorder.GetOrderByUserId(userobj.id).ToArray();
            lsvOrders.DataBind();

        }

        protected void lsvOrders_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (e.CommandName =="CancelOrder")
            {
                long orderId = Convert.ToInt64(e.CommandArgument);
                Order myOrder = new Order();
                try
                {
                    myOrder.CancelOrder(orderId);
                    divMessage.Visible = true;
                    divMessage.CssClass = "alert alert-success  alert-dismissible";
                    lblMessage.Text = "Cancel successful!";
                    BindData();

                }
                catch (Exception ex)
                {
                    divMessage.Visible = true;
                    divMessage.CssClass = "alert alert-danger  alert-dismissible";
                    lblMessage.Text = ex.Message;
                }



            }
        }

        protected void lsvOrders_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
        {
            //set current page startindex, max rows and rebind to false
            dp.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);

            //rebind List View
            BindData();
        }

       
    }


   
    
}